<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>个人信息管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
      <style>
          #thumb-box{
              position: relative;
          }
          #thumb{
              width: 200px;
              height: 290px;
              position: absolute;
              left: 328px;
              top: -252px;
              display: none;
          }
      </style>
  </head>
  
  <body>
    <div class="x-body" style="margin: 100px 200px">
        <form class="layui-form" >
            <input type="hidden" id="workerId" name="workerId" value="${worker.workerId}">
            <input type="hidden" id="workerDepartmentCode"  name="workerDepartmentCode" readonly value="${worker.workerDepartmentCode}">
          <div class="layui-form-item">
              <label for="workerName" class="layui-form-label">
                  <span class="x-red">*</span>姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="workerName" name="workerName" value="${worker.workerName}" readonly required="" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label class="layui-form-label">
                  <span class="x-red">*</span>性别
              </label>
              <div class="layui-input-inline">
                      <c:choose>
                          <c:when test="${worker.workerGender  == 1}">
                              <input type="text" id="workerGender" name="workerGender" value="男" readonly required="" lay-verify="required"
                                     autocomplete="off" class="layui-input">
                          </c:when>
                          <c:when test="${worker.workerGender  == 2}">
                              <input type="text" id="workerGender" name="workerGender" value="女" readonly required="" lay-verify="required"
                                     autocomplete="off" class="layui-input">
                          </c:when>
                      </c:choose>
              </div>
          </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>职位
                </label>
                <div class="layui-input-inline" id="workerDepartment">
                </div>
            </div>
          <div class="layui-form-item">
              <label for="workerPhone" class="layui-form-label">
                  <span class="x-red">*</span>手机号码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="workerPhone" name="workerPhone" value="${worker.workerPhone}" required="" lay-verify="phone"
                  autocomplete="off" class="layui-input" readonly>
              </div>
          </div>
            <div class="layui-form-item">
                <label for="workerSalary" class="layui-form-label">
                    <span class="x-red">*</span>基本工资
                </label>
                <div class="layui-input-inline">
                    <input type="number" id="workerSalary" name="workerSalary" value="${worker.workerSalary}" required="" lay-verify="salary"
                           autocomplete="off" class="layui-input" readonly>
                </div>
            </div>
          <div class="layui-form-item">
              <label for="workerIdCard" class="layui-form-label">
                  <span class="x-red">*</span>身份证号码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="workerIdCard" name="workerIdCard"  value="${worker.workerIdCard}" required="" lay-verify="idCard"
                  autocomplete="off" class="layui-input" readonly>
              </div>
          </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <a class="layui-btn layui-btn-normal" id="showBtn" onclick="showPasswordPart()">修改密码</a>
            </div>
            <div class="layui-form-item" id="oldWorkerPasswordPart" STYLE="display: none">
                <label for="oldWorkerPassword" class="layui-form-label">
                    <span class="x-red">*</span>原密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="oldWorkerPassword" name="oldWorkerPassword" required="" lay-verify="password"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div id="passwordPart">

            </div>
          <div class="layui-form-item">
              <label  class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="edit" id="editBtn" style="display: none" lay-submit="">
                  确认编辑
              </button>
          </div>
      </form>
    </div>
    <script>
        var isShow = false;
        function showPasswordPart(){
            if (!isShow){
                $("#passwordPart").append('<div class="layui-form-item" disabled="disabled">\n' +
                    '                <label for="workerPassword" class="layui-form-label">\n' +
                    '                    新密码\n' +
                    '                </label>\n' +
                    '                <div class="layui-input-inline">\n' +
                    '                    <input type="password" id="workerPassword" name="workerPassword" value="" lay-verify="password"\n' +
                    '                           autocomplete="off" class="layui-input">\n' +
                    '                </div>\n' +
                    '            </div>\n' +
                    '            <div class="layui-form-item">\n' +
                    '                <label for="workerPassword2" class="layui-form-label">\n' +
                    '                    确认密码\n' +
                    '                </label>\n' +
                    '                <div class="layui-input-inline">\n' +
                    '                    <input type="password" id="workerPassword2" name="workerPassword2" value="" lay-verify="password2"\n' +
                    '                           autocomplete="off" class="layui-input">\n' +
                    '                </div>\n' +
                    '            </div>')
                $("#showBtn").text("隐藏修改密码");
                $("#editBtn").show();
                $("#oldWorkerPasswordPart").show();
                isShow = true;
            }else {
                $("#passwordPart").empty();
                $("#showBtn").text("修改密码");
                $("#editBtn").hide();
                $("#oldWorkerPasswordPart").hide();
                isShow = false;
            }
        };
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
            ,layer = layui.layer;


            //自定义验证规则
            form.verify({
                salary:function(value){
                    if(value < 2000){
                        return '工资不得低于2000';
                    }
                }
              ,idCard:  [/^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/, '身份证输入不合法！']
                ,password: [/(.+){6,12}$/, '密码必须6到12位']
                , password2: function () {
                    if ($('#workerPassword').val() != $('#workerPassword2').val()) {
                        return '两次密码不一致';
                    }
                }
            });


            //监听提交
            form.on('submit(edit)', function(data){
                //发异步，把数据提交给java
                $.ajax({
                    type:"post",
                    url:"${pageContext.request.contextPath}/selfInfo?m=editSelfInfo",
                    data: data.field,
                    dataType:"json",
                    success:function (data) {
                        layer.msg(data.msg, function () {
                            if (data.code === 200){
                                console.log(data.data)
                                window.parent.location.reload();
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            }
                        });

                    }
                });
            return false;
          });

            // 获取分类数据
            $.ajax({
                type:"post",
                url:"${pageContext.request.contextPath}/department?m=getAllDepartment",
                dataType:"json",
                success:function (data) {
                    if (data.code === 200){
                        $("#workerDepartment").empty();
                        $(data.data).each(function () {
                            if ($("#workerDepartmentCode").val() === this.departmentCode){
                                $('#workerDepartment').append("                            <input type=\"text\" id=\"workerDepartmentName\" name=\"workerDepartmentName\" value='"+this.departmentName+"'  readonly  required=\"\" lay-verify=\"required\"\n" +
                                    "autocomplete=\"off\" class=\"layui-input\">")
                            }
                        });
                        // 重新渲染
                        form.render('select');
                    }
                }
            });
        });


    </script>

  </body>

</html>